home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Utilities / ResEdit / Examples / PExamples / Source / ResXXXXEd.p < prev    next >
Text File  |  2022-08-05  |  9KB  |  301 lines

  1. {
  2. File ResXXXXEd.p
  3.  
  4. Copyright Apple Computer, Inc. 1985-1989
  5. All rights reserved.
  6. }
  7.  
  8. UNIT ResXXXXed;
  9. {XXXX Editor for ResEdit}
  10.  
  11. INTERFACE
  12.  
  13.     USES    Memtypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
  14.                 ResEd;
  15.  
  16.         {$R-} {Range checking off }
  17.  
  18.     TYPE
  19.         rXXXXPtr = ^rXXXXRec;
  20.         rXXXXHandle = ^rXXXXPtr;
  21.         rXXXXRec = RECORD
  22.                                  father: ParentHandle;    { Back ptr to dad }
  23.                                  name: str64;                     { The name of this editor }
  24.                                  windPtr: WindowPtr;        { This view's window }
  25.                                  rebuild: BOOLEAN;            { Set TRUE if things have changed }
  26.                                  hXXXX: Handle;                    { The resource we are working on }
  27.                              END; {rXXXXRec}
  28.  
  29.     PROCEDURE EditBirth(thing: Handle; Dad: ParentHandle);
  30.  
  31.     PROCEDURE PickBirth(t: ResType; Dad: ParentHandle);
  32.  
  33.     PROCEDURE DoEvent(VAR Evt: EventRecord; myXXXX: rXXXXHandle);
  34.  
  35.     PROCEDURE DoInfoUpdate(oldID, newID: INTEGER; myXXXX: rXXXXHandle);
  36.  
  37.     PROCEDURE DoMenu(Menu, Item: INTEGER; myXXXX: rXXXXHandle);
  38.  
  39. IMPLEMENTATION
  40.  
  41.     CONST
  42.         windowWidth = 300;
  43.         windowHeight = 100;
  44.  
  45.         deleteChr = CHR(8);
  46.         
  47.         sizeOfMyResource = 10;
  48.         
  49.         {- - -    -  - -    -  -    - -  -    - - -  - -    - - -  -    - -  -    -}
  50.  
  51.     { Fix up the window name and title for our window. }
  52.     PROCEDURE GetNameAndTitle(VAR windowTitle, windowName: STR255; thing: Handle);
  53.  
  54.         BEGIN
  55.         windowTitle := '';
  56.         SetETitle(thing, windowTitle);
  57.         windowName := Concat('XXXX', windowTitle);
  58.         windowTitle := Concat('XXXX', windowTitle);
  59.         END;
  60.  
  61.  { **************************************************************************************** }
  62.  
  63.     PROCEDURE EditBirth(thing:Handle; dad:ParentHandle);
  64.  
  65.         VAR
  66.             myXXXX: rXXXXHandle;
  67.             myWindow: WindowPtr;
  68.             windowTitle, newName: STR255;
  69.  
  70.         BEGIN {EditBirth}
  71.         { Prepare window title and request creation of a new window }
  72.         GetNameAndTitle(windowTitle, newName, thing);
  73.         myWindow := EditorWindSetup(FALSE, windowWidth, windowHeight, windowTitle, newName, TRUE, dad);
  74.         
  75.         { If we got a new window, then start up the editor }
  76.         IF myWindow <> NIL THEN
  77.             BEGIN
  78.             IF (GetHandleSize(thing)) = 0 THEN { This was called via a NEW, so make a new resource }
  79.                 FixHand(sizeOfMyResource, thing);
  80.  
  81.             { Get memory for and handle to our instance record }
  82.             myXXXX := rXXXXHandle(NewHandle(SIZEOF(rXXXXRec)));
  83.             BubbleUp(Handle(myXXXX));
  84.             HLock(Handle(myXXXX));
  85.  
  86.             WITH myXXXX^^ DO
  87.                 BEGIN
  88.                 { Put information about this incarnation of the editor and the window it is }
  89.                 { serving into our record.(always passed around in the handle myXXXX).  }
  90.                 
  91.                 windPtr := myWindow;
  92.                 father := dad;
  93.                 name := newName;
  94.                 hXXXX := thing;
  95.                 
  96.                 { Let the main program know who is to manage this window by giving it both     }
  97.                 { our resource ID number and our instance record handle.        }
  98.                 WITH WindowPeek(myWindow)^ DO
  99.                     BEGIN
  100.                     windowKind := ResEdID;
  101.                     refCon := ORD(myXXXX);
  102.                     END; {WITH}
  103.                 END; {WITH}
  104.                 
  105.             { Set up any menus,views, etc. for this window here. }
  106.             
  107.             HUnlock(Handle(myXXXX));
  108.             END; { IF myWind <> NIL }
  109.         END; { EditBirth }
  110.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  111.  
  112.     { Not used for editors. }
  113.     PROCEDURE PickBirth(t:ResType;Dad:ParentHandle);
  114.  
  115.         BEGIN { PickBirth }
  116.         END;     { PickBirth }
  117.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  118.  
  119.     PROCEDURE DoEvent(VAR Evt:EventRecord; myXXXX:rXXXXHandle);
  120.  
  121.         VAR
  122.             MousePoint: Point;
  123.             act: BOOLEAN;
  124.  
  125.         BEGIN {DoEvent}
  126.         BubbleUp(Handle(myXXXX));         { Move our item up in memory }
  127.         HLock(Handle(myXXXX));                 { Lock it down }
  128.         WITH myXXXX^^ DO
  129.             BEGIN
  130.             { Handle event passed to us by main program.  Just like a 'real' event loop, except…
  131.                  there is no loop and we don't have to handle as much because the main program
  132.                  will do all the stuff that doesn't apply to us. }
  133.                 
  134.             MousePoint := Evt.where;        { Point at which the event occured }
  135.             SetPort(windPtr);                        { Set the port to our window }
  136.             GlobalToLocal(MousePoint);    { Convert event location to local coords }
  137.             
  138.             CASE Evt.what OF
  139.                 mouseDown:
  140.                     BEGIN
  141.                                                 { Do any special mouse down processing here. }
  142.                     END; { mouseDown }
  143.                 activateEvt:
  144.                     BEGIN
  145.                     AbleMenu(fileMenu, filetop);
  146.                     act := ODD(Evt.modifiers);
  147.                     IF act THEN
  148.                         BEGIN
  149.                                                 { Do any activate processing here (such as inserting a menu). }
  150.                         END
  151.                     ELSE
  152.                         BEGIN
  153.                                                 { Do any deactivate processing here (such as deleting a menu). }
  154.                         END;
  155.                     DrawMenuBar;    { To make sure that everything is drawn properly. }
  156.                     END {activateEvt} ;
  157.                 updateEvt:
  158.                     BEGIN
  159.                                                 { Do the appropriate update processing here.  Remember that 
  160.                                                     BeginUpdate has already been called. }
  161.                     PaintRect(windPtr^.portrect);
  162.                     END; {updateEvt}
  163.                 keyDown:
  164.                     BEGIN
  165.                                                 { Do any key processing here. }
  166.                     
  167.                     { Convert the delete character into a clear command. }
  168.                     IF (CHR(band(evt.message, charCodeMask)) = deleteChr) THEN
  169.                         DoMenu (editMenu, clearItem, myXXXX)
  170.                     END; {keyDown}
  171.                 
  172.                 nullEvent:
  173.                     BEGIN
  174.                                             { Do any null event processing here (such as blinking a cursor).    }
  175.                     END;
  176.                 END;    { CASE evt.what }
  177.             END;         { WITH myXXXX^^ }
  178.             
  179.         HUnlock(Handle(myXXXX));
  180.         END;             { DoEvent }
  181.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  182.  
  183.     PROCEDURE DoInfoUpdate(oldID,newID:INTEGER;myXXXX:rXXXXHandle);
  184.  
  185.         VAR
  186.             windowTitle, windowName: STR255;
  187.  
  188.         BEGIN { DoInfoUpdate }
  189.         WITH myXXXX^^ DO
  190.             BEGIN 
  191.             { Since our ID has changed, we need to change our window title }
  192.             GetNameAndTitle (windowTitle, windowName, Handle(hXXXX));
  193.             GetWindowTitle (windowTitle, windowName, TRUE, father);
  194.             name := windowName;                                { Save the new name in my data structure. }
  195.             SetWTitle(windPtr, windowtitle);    { Set the new window title. }
  196.     
  197.             { Now, let our father object know that our ID has been changed }
  198.             father^^.rebuild := TRUE;                    { Rebuild the picker list. }
  199.             CallInfoUpdate(oldID, newID, father^^.wind^.refCon, father^^.wind^.windowKind);
  200.             END; { WITH myXXXX^^ }
  201.         END; { DoInfoUpdate }
  202.     {- -    -  - - -    - -  - - -    -  - -    -  -    - -  -    - - -  - -}
  203.  
  204.     PROCEDURE DoMenu(Menu, Item:INTEGER; myXXXX:rXXXXHandle);
  205.  
  206.         VAR
  207.             saveRefNum: INTEGER;
  208.             hTemp: Handle;
  209.  
  210.         { Close down the window and get rid of any memory that has been allocated. }
  211.         PROCEDURE DoClose;
  212.  
  213.             BEGIN
  214.             WITH myXXXX^^ DO
  215.                 BEGIN
  216.                 CloseWindow(windPtr);
  217.                 WindReturn(windPtr);                { Mark the window record as being available }
  218.                 SetTheCursor (arrowCursor); { Make sure the cursor is the arrow cursor }
  219.                 
  220.                 { Delete any menus that we added and the redraw menu bar     }
  221.                 { Be sure to dispose of any handles you are done with    }
  222.                 
  223.                 { Release the resource if we were launched from a picker }
  224.                 IF (father^^.name[1] <> editorNameChr) THEN
  225.                     ReleaseResource (Handle(hXXXX));  { Let it be free (if it is not changed)! }
  226.                 END; { WITH myXXXX^^ }
  227.             DisposHandle(Handle(myXXXX));
  228.             END; { DoClose }
  229.  
  230.         BEGIN {DoMenu}
  231.         BubbleUp(Handle(myXXXX));
  232.         HLock(Handle(myXXXX));
  233.         WITH myXXXX^^ DO
  234.             BEGIN
  235.             SetPort(windPtr); { Set the port to our window }
  236.             
  237.             { Again, we handle the menu stuff just as we would in a 'real' application
  238.                 except that we only have to handle those items that apply to our editor. }
  239.             CASE Menu OF
  240.                 fileMenu:
  241.                     CASE Item OF
  242.                         CloseItem:
  243.                             BEGIN
  244.                             DoClose;             {    Close our window }
  245.                             EXIT(DoMenu); {    Return immediately since our resource is gone!    }
  246.                             END; { CloseItem }
  247.                             
  248.                         saveItem:                { Pass the save on to other windows. }
  249.                             PassMenu(fileMenu, saveItem, ParentHandle(myXXXX));
  250.                 
  251.                         RevertItem:
  252.                             BEGIN
  253.                             IF NeedToRevert (windPtr, Handle(hXXXX)) THEN
  254.                                 BEGIN
  255.                                 { The area under the window will need to be updated }
  256.                                 InvalRect(windPtr^.portrect);
  257.                                 
  258.                                 { We will need to restore the current resource file reference number when we are done here.     }
  259.                                 saveRefNum := CurrentRes;
  260.                                 { We are going to be using the resource file we came from. }
  261.                                 UseResFile(HomeResFile(Handle(hXXXX)));
  262.                                 
  263.                                 { Read in the old copy from disk (see documentation for revertResource).  Clear it out 
  264.                                     unless this  was a newly created resource, in which case don't. }
  265.                                 IF NOT RevertThisResource(ParentHandle(myXXXX), Handle(hXXXX)) THEN
  266.                                     BEGIN        { The resource was newly added so we need to remove it. }
  267.                                     { Save the handle so that we can dispose it later. }
  268.                                     hTemp := Handle (hXXXX);
  269.                                     
  270.                                     { Make sure that the picker list is rebuilt to remove this item. }
  271.                                     myXXXX^^.father^^.rebuild := TRUE;
  272.                                     
  273.                                     DoClose;                                { Close the window. }
  274.                                     RemoveResource (hTemp);    { Dispose the resource itself. }
  275.                                     EXIT(DoMenu);
  276.                                     END; {IF NOT RevertResource…}
  277.                                 
  278.                                 UseResFile(saveRefNum);    { Go back to using the old resource file. }
  279.                                 END;
  280.                             END; { RevertItem }
  281.                             
  282.                         GetInfoItem:
  283.                             BEGIN
  284.                             { Put up the GetInfo window. }
  285.                             ShowInfo(Handle(hXXXX), ParentHandle(myXXXX));
  286.                             END; { GetInfoItem }
  287.                     END; {FileMenu: CASE Item OF}
  288.                 EditMenu:
  289.                     CASE Item OF
  290.                         { Implement the edit menu here. }
  291.                         CutItem: ;
  292.                         CopyItem: ;
  293.                         PasteItem: ;
  294.                         ClearItem: ;
  295.                     END; { EditMenu }
  296.                 END; { CASE Menu OF }
  297.             END; { WITH myXXXX^^}
  298.         HUnlock(Handle(myXXXX));
  299.         END; {DoMenu}
  300. END.
  301.